package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.rec.be.CompromisoPago;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class CompromisoPagoDelegate {

    private CompromisoPagoFacadeLocal local;

    public CompromisoPagoDelegate() {
        local = lookupCompromisoPagoFacade();
    }

    private CompromisoPagoFacadeLocal lookupCompromisoPagoFacade() {
        try {
            Context c = new InitialContext();
            return (CompromisoPagoFacadeLocal) c.lookup("java:comp/env/CompromisoPagoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public void crear(CompromisoPago CompromisoPago) throws Exception {
        try {
            local.create(CompromisoPago);
        } catch (Exception e) {
            local = lookupCompromisoPagoFacade();
            throw new Exception("Crear CompromisoPago. " + e.getMessage());
        }
    }

    public void editar(CompromisoPago CompromisoPago) throws Exception {
        try {
            local.edit(CompromisoPago);
        } catch (Exception e) {
            local = lookupCompromisoPagoFacade();
            throw new Exception("Editar CompromisoPago. " + e.getMessage());
        }
    }
    public void eliminar(CompromisoPago compromisoPago) throws Exception {
        try {
            local.remove(compromisoPago);
        } catch (Exception e) {
            local = lookupCompromisoPagoFacade();
            throw new Exception("Eliminar CompromisoPago. " + e.getMessage());
        }
    }
    public CompromisoPago buscar(long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupCompromisoPagoFacade();
            throw new Exception("Buscar CompromisoPago. " + e.getMessage());
        }
    }
}
